package com.yuanqi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanqi.entity.WareTransferItem;
import com.yuanqi.mapper.WareTransferItemMapper;
import com.yuanqi.service.WareTransferItemService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @author HP
* @description 针对表【ware_transfer_item(库存调拨明细)】的数据库操作Service实现
* @createDate 2025-08-28 16:00:00
*/
@Service
public class WareTransferItemServiceImpl extends ServiceImpl<WareTransferItemMapper, WareTransferItem>
    implements WareTransferItemService {

    @Override
    public List<WareTransferItem> getItemsByTransferId(Long transferId) {
        LambdaQueryWrapper<WareTransferItem> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WareTransferItem::getTransferId, transferId);
        queryWrapper.orderByAsc(WareTransferItem::getId);
        return this.list(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveItems(List<WareTransferItem> items) {
        if (items == null || items.isEmpty()) {
            return true;
        }
        
        return this.saveBatch(items);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteItemsByTransferId(Long transferId) {
        LambdaQueryWrapper<WareTransferItem> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WareTransferItem::getTransferId, transferId);
        return this.remove(queryWrapper);
    }
}